package com.zp.self.module.level_5_设计模式.行为型模式.Ⅹ_备忘录模式.黑箱模式;

import lombok.Data;

import java.util.Random;

/**
 * @author ：by Zeng Peng
 * @date ：Created 2022/7/7 20:50
 * @description ：
 */
@Data
public class GameRole {
    private int  bloodVolume;
    private int  aggressivity;
    private int  defense;

    public GameRole(int bloodVolume, int aggressivity, int defense) {
        this.bloodVolume = bloodVolume;
        this.aggressivity = aggressivity;
        this.defense = defense;
    }

    public void fight(){
        Random random = new Random();
        this.bloodVolume = random.nextInt(100);
        this.aggressivity = random.nextInt(100);
        this.defense =  random.nextInt(100);
    }

    public RoleStateMemorandum saveState(){
        return new RoleStateMemorandum(bloodVolume,aggressivity,defense);
    }


    public void recover(Memorandum memorandum) {
        RoleStateMemorandum roleState = (RoleStateMemorandum)memorandum;
        this.bloodVolume = roleState.getBloodVolume();
        this.aggressivity = roleState.getAggressivity();
        this.defense =  roleState.getDefense();

    }

    @Data
    private class RoleStateMemorandum implements Memorandum{

        private int  bloodVolume;
        private int  aggressivity;
        private int  defense;

        public RoleStateMemorandum(int bloodVolume, int aggressivity, int defense) {
            this.bloodVolume = bloodVolume;
            this.aggressivity = aggressivity;
            this.defense = defense;
        }
    }
}
